//
//  PersonalDetailView.swift
//  FeastBooking
//
//  Created by Imon on 2017/10/2.
//  Copyright © 2017年 Imon. All rights reserved.
//

import UIKit

class PersonalInformBar: UIView {

    let titleLabel: UILabel = {
        let label = UILabel()
        label.font = AppFont(size: 14)
        label.textColor = UIColor.lightGray
        return label
    }()
    
    let valueLabel: UILabel = {
        let label = UILabel()
        label.font = AppFont(size: 14)
        label.textColor = UIColor.gray
        return label
    }()
    
    let pointerLabel: UIImageView = {
        let imageView = UIImageView()
        imageView.contentMode = .scaleAspectFit
        imageView.image = UIImage(named: "pointer")
        return imageView
    }()
    
    let saperator: UIView = {
        let view = UIView()
        view.backgroundColor = saperatorColor
        return view
    }()
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        self.backgroundColor = UIColor.white
        self.addSubview(titleLabel)
        self.addSubview(valueLabel)
        self.addSubview(pointerLabel)
        self.addSubview(saperator)
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    override func layoutSubviews() {
        super.layoutSubviews()
        let pointerWidth:CGFloat = 13
        let textMaxSize = CGSize(width: bounds.width, height: 40)
        let titleWidth = TextSize.textSize(text: titleLabel.text!, font: titleLabel.font, maxSize: textMaxSize).width
        let valueWidth = TextSize.textSize(text: valueLabel.text!, font: valueLabel.font, maxSize: textMaxSize).width
        titleLabel.frame = UIEdgeInsetsInsetRect(bounds, UIEdgeInsetsMake(5, 15, 5, bounds.width - 15 - titleWidth))
        pointerLabel.frame = UIEdgeInsetsInsetRect(bounds, UIEdgeInsetsMake(5, bounds.width - 10 - pointerWidth, 5, 10))
        valueLabel.frame = UIEdgeInsetsInsetRect(bounds, UIEdgeInsetsMake(5, pointerLabel.frame.origin.x - 10 - valueWidth, 5, pointerWidth + 20))
        saperator.frame = UIEdgeInsetsInsetRect(bounds, UIEdgeInsetsMake(bounds.height - 0.5, 10, 0, 10))
    }
}

class AvatarBar: UIView {
    
    let avatar: UIImageView = {
        let view = UIImageView()
        view.image = UIImage(named: "r1")
        view.contentMode = .scaleAspectFill
        return view
    }()
    
    let titleLabel: UILabel = {
        let label = UILabel()
        label.font = AppFont(size: 14)
        label.textColor = UIColor.lightGray
        label.text = LanguageHelper.getString(key: "AVATAR")
        return label
    }()
    
    let pointerLabel: UIImageView = {
        let imageView = UIImageView()
        imageView.contentMode = .scaleAspectFit
        imageView.image = UIImage(named: "pointer")
        return imageView
    }()
    
    let saperator: UIView = {
        let view = UIView()
        view.backgroundColor = saperatorColor
        return view
    }()
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        self.backgroundColor = UIColor.white
        self.addSubview(avatar)
        self.addSubview(titleLabel)
        self.addSubview(pointerLabel)
        self.addSubview(saperator)
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    override func layoutSubviews() {
        super.layoutSubviews()
        let pointerWidth: CGFloat = 13
        let avatarWidth: CGFloat = self.bounds.height - 10
        let textMaxSize = CGSize(width: bounds.width, height: 40)
        let titleWidth = TextSize.textSize(text: titleLabel.text!, font: titleLabel.font, maxSize: textMaxSize).width
        titleLabel.frame = UIEdgeInsetsInsetRect(bounds, UIEdgeInsetsMake(5, 15, 5, bounds.width - 15 - titleWidth))
        pointerLabel.frame = UIEdgeInsetsInsetRect(bounds, UIEdgeInsetsMake(5, bounds.width - 10 - pointerWidth, 5, 10))
        avatar.frame = UIEdgeInsetsInsetRect(bounds, UIEdgeInsetsMake(5, pointerLabel.frame.origin.x - 10 - avatarWidth, 5, pointerWidth + 20))
        saperator.frame = UIEdgeInsetsInsetRect(bounds, UIEdgeInsetsMake(bounds.height - 0.5, 10, 0, 10))
        avatar.layer.cornerRadius = avatar.frame.height / 2
        avatar.layer.masksToBounds = true
    }
}
